package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.ShippingDao;
import cn.itcast.domain.cargo.IncasementProxy;
import cn.itcast.service.cargo.ShippingService;
import cn.itcast.vo.ContractProductVo;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.UUID;

@Service
public class ShippingServiceImpl implements ShippingService {

    @Autowired
    private ShippingDao shippingDao;

    @Override
    public PageInfo<IncasementProxy> findByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<IncasementProxy> list = shippingDao.findAll();
        PageInfo<IncasementProxy> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public boolean delete(String shippindOrderId) {
        int state = shippingDao.findStateByShippindOrderId(shippindOrderId);
        if(state==0){
            shippingDao.delete(shippindOrderId);
            return true;
        }else{
            return false;
        }
    }

    @Override
    public void add(IncasementProxy incasementProxy) {
        incasementProxy.setShippindOrderId(UUID.randomUUID().toString());
        shippingDao.insertSelective(incasementProxy);
    }

    @Override
    public List<IncasementProxy> findAll(String deptName) {
        return shippingDao.findAll1(deptName);
    }

    @Override
    public IncasementProxy findById(String shippingOrderId) {
        return shippingDao.findById(shippingOrderId);
    }


    @Override
    public void updateState(String shippindOrderId, int state) {
        shippingDao.updateState(shippindOrderId,state);
    }

}
